package main

import (
	"fmt"
	"math"
)

type Employee struct {
	name     string
	salary   int
	currency string
}

type Rectangle struct {
	width, height float64
}
type Circle struct {
	radius float64
}

type Human struct {
	name  string
	age   int
	phone string
}
type Student struct {
	Human  //匿名字段
	school string
}
type Work struct {
	Human   //匿名字段
	company string
}

func main() {
	emp01 := Employee {
		name:     "Sam Adolf",
		salary:   5000,
		currency: "$",
	}

	emp01.display()
	fmt.Println()

	// 可以定义相同的方法名
	r01 := Rectangle{12, 2}
	fmt.Println("Area of r01 is: ", r01.area())

	c01 := Circle{10}
	fmt.Println("Area of c01 is: ", c01.area())

	// ”继承”中的方法
	mark := Student{Human{"Mark", 25, "222-222-YYYY"}, "MIT"}
	sam := Work{Human{"Sam", 45, "111-888-XXXX"}, "Golang Inc"}
	mark.SayHi()
	// sam.SayHi()

	// method重写
	fmt.Println("--------------------------------------------")
	sam.SayHi()
}

/*方法有调用类型*/
func (e Employee) display()  {

	fmt.Printf("Salary of %s is %s%d", e.name, e.currency, e.salary)

}
//该 method 属于 Circle 类型对象中的方法
func (c Circle) area() float64  {
	return c.radius * c.radius * math.Pi
}

//该 method 属于 Rectangle 类型对象中的方法
func (r Rectangle) area() float64  {
	return r.width * r.height
}

/*Human 类型的方法*/
func (h *Human) SayHi() {
	fmt.Printf("Hi, I am %s you can call me on %s\n", h.name, h.phone)
}

/*Work 类型的方法*/
func (w *Work) SayHi() {
	fmt.Printf("Hi, I am %s, I work at %s. Call me on %s\n", w.name, w.company, w.phone)
}
